# app/services/family/recipe.py
from typing import Optional, List
from app.core.crud import CRUDBase
from app.models.family.recipe import Recipe
from app.schemas.family.recipe import RecipeCreate, RecipeUpdate
from tortoise.expressions import Q

class RecipeService(CRUDBase[Recipe, RecipeCreate, RecipeUpdate]):
    def __init__(self):
        super().__init__(model=Recipe)

    async def get_recipe_by_family(self, recipe_id: int, family_id: int) -> Optional[Recipe]:
        """根据食谱ID和家庭ID获取食谱"""
        return await self.model.filter(id=recipe_id, family_id=family_id, is_deleted=False).first()

    async def list_recipes_by_family(self, family_id: int, page: int = 1, page_size: int = 10) -> List[Recipe]:
        """根据家庭ID获取食谱列表"""
        return await self.model.filter(family_id=family_id, is_deleted=False).offset((page-1)*page_size).limit(page_size)

recipe_service = RecipeService()